#include <unistd.h>
#include <stdio.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <string.h>

int main() {
  int id = shmget(0x8888, 0, 0);
  printf("id = %d\n", id);
  
  if (id < 0) {
    perror("shmget");
    return -1;
  }

  char *buf = shmat(id, NULL, 0);
  printf("buf = %p\n", buf);
  if (buf == (char*)-1) {
    perror("shmat");
    return -1;
  }

  printf("content = %s\n", buf);

  if (shmdt(buf) < 0) {
    perror("shmdt");
    return -1;
  }


  if (shmctl(id, IPC_RMID, NULL) < 0) {
    perror("shmctl");
    return -1;
  }
  return 0;
}
